package cn.kimming.system.controller;

import cn.kimming.common.dto.RoomPlanDTO;
import cn.kimming.common.pojo.Employee;
import cn.kimming.common.pojo.RoomPlan;
import cn.kimming.common.util.Result;
import cn.kimming.common.vo.RoomPlanVO;
import cn.kimming.common.vo.RoomVO;
import cn.kimming.service.IRoomPlanService;
import cn.kimming.service.IRoomService;
import com.alibaba.fastjson.JSONObject;
import netscape.javascript.JSObject;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author 刘铭轩
 * date 2021-06-02
 */
@RestController
@RequestMapping("/roomplan")
public class RoomPlanController {
    @Autowired
    private IRoomPlanService roomPlanService;
    @GetMapping("/futureDate/{futureDate}")
    public Result findAll(@PathVariable String futureDate) {
        List<RoomPlanVO> list = roomPlanService.findVOByFutureDate(futureDate);
        return new Result(true, "查询成功").addData("list", list);
    }

    @GetMapping("/todayprice")
    public Result showTodayPrice() {
        List<JSONObject> list = roomPlanService.showTodayPrice();
        return new Result(true, "查询成功").addData("list", list);
    }

    @PutMapping
    public Result update(@Valid @RequestBody RoomPlanDTO dto) {
        RoomPlan bo = new RoomPlan();
        BeanUtils.copyProperties(dto, bo);
        roomPlanService.updateDiscountAndPrice(bo);
        return new Result(true, "更新成功");
    }


}
